"""
运算符相关的魔法方法
"""

class Student:
    def __init__(self,name,age):
        self.name = name
        self.age = age

    # 判断是否相等
    def __eq__(self,other):
        return self.name == other.name and self.age == other.age

    # 表示大于
    def __gt__(self,other):
        return self.age > other.age

    # 表示小于
    def __lt__(self,other):
        return self.age < other.age

    # 加
    def __add__(self,other):
        return Student(self.name, self.age + other.age)

    # 减
    def __sub__(self,other):
        return Student(self.name, self.age - other.age)


    def __repr__(self):
        return (f'Student = (name={self.name},age={self.age})')




if __name__ == '__main__':
   #  s1 = Student('聂茹凤',19)
   #  s2 = Student('聂茹凤',19)
   #
   #  print(s1)
   #  print(s2)
   #
   # # print(s1 == s2) # == 判断的是地址是否相同
   #  print(s1 == s2)

   s1 = Student('聂茹凤', 19)
   s2 = Student('谭欣雨', 20)

   print(s2 > s1)
   print(s1 + s2)